

local itemName=nil
local modelName=nil
local spawnInfo=nil
local readySpawn=false


function StartSpawn()
    local newItem = CreateItem(itemName, nil, nil )
    local dropItem= CreateItemOnPositionForLaunch( thisEntity:GetAbsOrigin(), newItem)
    newItem:LaunchLoot(false, 0,0, thisEntity:GetAbsOrigin())
    modelName=dropItem:GetModelName()
    --dropItem:EmitSound(SoundsNames.item_drop)
    return 5
end

function OnTriggerThink_Timer()
    if spawnInfo==nil then
        if type(SpawnItemConfig) == "table"  then
            spawnInfo= SpawnItemConfig[itemName]
        end
        return 3
    end
    if modelName~=nil then
        local items = Entities:FindByModelWithin(nil, modelName,thisEntity:GetAbsOrigin(),200)
        if items~=nil then
            return 3
        else
            if readySpawn==true then
                readySpawn=false
                return StartSpawn()
            else
                readySpawn=true
                return spawnInfo.intervalTime
            end
        end
    else
        if readySpawn==true then
            readySpawn=false
            return StartSpawn()
        else
            readySpawn=true
            local intervalTime=spawnInfo.firstRefreshTime-GameRules:GetDOTATime(false,false)
            if intervalTime<0 then
                intervalTime=5
            end
            return intervalTime
        end
    end
    return 3
end

itemName=string.gsub(thisEntity:GetName(),"%d.","")
--print(thisEntity:GetName(),itemName)
thisEntity:SetThink( "OnTriggerThink_Timer", 6)